#include <stdio.h>
#include "display.h"

//u8 bitMatrix[8][128];
//u16 high[128];




void genBitMatrix(u16 high[],u8 bitMatrix[][128])
{
	
	u8 i;
	u8 j;
	static u16 fall_point[32];
	u16 dispColumn[32];

	
		//high[0]
	//bitMatrix[0-7][0] page byte;
	
	//high ==>bit 
	u32 temp_32bits_high;
	u32 temp_32bits_low;
	u32 temp_allFF = ~0;

	

	for(i = 0; i <32;i++)
	{
		dispColumn[i] = high[(i<<2)+2];
		if(fall_point[i]<dispColumn[i])
		{
			fall_point[i]=dispColumn[i];
		}
		else
		{
			fall_point[i]-=3;
		}
		//printf("fall[%d]:%x\r\n",i,fall_point[i]);
	}	
	
	for(i = 0; i <32;i++){
		if(dispColumn[i] >32){
			temp_32bits_high = temp_allFF<<(dispColumn[i]-32); //high
			temp_32bits_low =0;		//low allFF
		}
		else
		{
			//bits_high = all0
			temp_32bits_high = temp_allFF;
			temp_32bits_low = temp_allFF <<(dispColumn[i]) ; //low 
		}	
		if(fall_point[i] >64){
			
			fall_point[i] =64;
		}else if(fall_point[i] >= 34){ 
			temp_32bits_high &=~(( 0x7 )<<(fall_point[i]-32-2)); //high
		}
		else if( fall_point[i] <=33 && fall_point[i] >=32)
		{	
			temp_32bits_high &=~(( 0x7 ) >>(34-fall_point[i])); //high
			temp_32bits_low &= ~(( 0x7 ) <<(fall_point[i]-2)) ; //low 
		}
		else if( fall_point[i] >4)// 0~31
		{
			temp_32bits_low &= ~(( 0x7 ) <<(fall_point[i]-2)) ; //low 
		}else
		{
			fall_point[i] =4;			
		}
		
		for(j = 0; j < 3;j++){
			//printf("Matrix %d=>%x %x\r\n",(i<<2)+j,temp_32bits_high,temp_32bits_low);
			bitMatrix[0][(i<<2)+j] = (temp_32bits_low  ) & 0xff;
			bitMatrix[1][(i<<2)+j] = (temp_32bits_low >>8  ) & 0xff;	
			bitMatrix[2][(i<<2)+j] = (temp_32bits_low >>16 ) & 0xff;
			bitMatrix[3][(i<<2)+j] = (temp_32bits_low >>24 ) & 0xff;
			
			bitMatrix[4][(i<<2)+j] = (temp_32bits_high  ) & 0xff;
			bitMatrix[5][(i<<2)+j] = (temp_32bits_high >>8  ) & 0xff;
			bitMatrix[6][(i<<2)+j] = (temp_32bits_high >>16  ) & 0xff;
			bitMatrix[7][(i<<2)+j] = (temp_32bits_high >>24  ) & 0xff;
		}
	}
}

